package app.netant.book.ajman;

import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;

public class AjmanDetail extends BaseDetail {

	public AjmanDetail(String netSite) {
		super(netSite);
		this.preHref = "http://www.ajman.cc";
	}

	@Override
	public void analyseTitle() {
		Elements parts = this.select("#main .txt_top .xiazai .txt_info .show_num h1");
		if(parts.size()>0){
			String title = parts.get(0).text();
			int idx = title.indexOf("txt");
			if(idx>0){
				title = title.substring(0,idx);
			}
			System.out.println("【Title】:"+title);
			String name = this.entity.getNovelName();
			if(name == null || "".equals(name)){
				this.entity.setNovelName(title);
				this.entity.setNovelFullName(title+".txt");
			}
		}
		
		Elements datePs = this.select("#main .txt_top .xiazai .txt_info .show_num p.update");
		if(datePs.size()>0){
			String tmp = datePs.get(0).text();
			int idx = tmp.indexOf("更新时间：");
			if(idx>0){
				String date = tmp.substring(idx+5,idx+15);
				System.out.println("【Date】:"+date);
				this.entity.setNovelDate(date);
			}
		}
	}

	@Override
	public void analyseTags() {
		Elements parts = this.select("#main .txt_top .xiazai .txt_info .show_num ul li");
		for(int i=0;i<parts.size();i++){
			String tags = parts.get(i).text();
			int idx = tags.indexOf("：");
			if(idx>0){
				String tagName = tags.substring(0,idx);
				String tagValue = tags.substring(idx+1);
				System.out.println("【Tag】:"+tagName+"="+tagValue);
				this.entity.setTag(tagName, tagValue);
			}
		}
	}

	@Override
	public void analyseMemo() {
		Elements parts = this.select("#main .txt_top .xiazai .txt_info .intro .txt_description p");
		if(parts.size()>0){
			String memo = parts.get(0).text();			
			System.out.println("【Memo】:"+memo);
			this.entity.setNovelMemo(memo);
		}	
	}

	@Override
	public void analyseHref() {
		Elements parts = this.select("#main #down_txt_url .txt_down a");
		if(parts.size()>0){
			String href = parts.get(0).attr("href");
			System.out.println("【Href】:"+href);
			this.entity.setDownPath(href);
		}
	}
	
	@Override
	public void analyseType() {
		Elements parts = this.select("#main .crumbs a");
		if(parts.size()>1){
			String type = parts.get(1).text();
			int idx = type.indexOf("小说");
			if(idx>0){
				type = type.substring(0,idx);
			}
			System.out.println("【Type】:"+type);
			this.entity.setNovelType(type);
		}
	}
	
	public static void main(String[] args) {
		AjmanDetail detail = new AjmanDetail("http://www.ajman.cc/txt/xiazai92380.html");
		detail.test();
	}



}
